package com.vanysoft.business.sys.service.impl;

import com.vanysoft.business.sys.dao.MenuMapper;
import com.vanysoft.business.sys.entity.Menu;
import com.vanysoft.business.sys.service.MenuService;
import com.vanysoft.framework.config.database.BaseServiceImpl;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 角色服务类实现
 *
 * @author qi_ma
 */
@Service
public class MenuServiceImpl extends BaseServiceImpl<MenuMapper, Menu> implements MenuService {

    @Override
    public List<Menu> selectByUserId(String userId) {
        return baseMapper.selectByUserId(userId);
    }

    @Override
    public List<Menu> selectAll(String userId) {
        return baseMapper.selectAll(userId);
    }

    @Override
    public List<String> selectIdsByRoleId(String roleId) {
        return baseMapper.selectIdsByRoleId(roleId);
    }

    @Override
    public boolean saveByRoleIdAndMenuIds(String roleId, String[] menuIds) {
        int i = baseMapper.deleteByRoleId(roleId);
        if (menuIds != null && menuIds.length > 0) {
            for (String menuId : menuIds) {
                i += baseMapper.insertRoleMenu(roleId, menuId);
            }
        }
        return retBool(i);
    }

}
